
<%@ include file="/html/portlet/ext/chart/init.jsp" %>
<liferay-portlet:renderURL var="chartURL" windowState="<%= WindowState.MAXIMIZED.toString() %>">
	<portlet:param name="struts_action" value="/ext/chart/add_chart" />	
</liferay-portlet:renderURL>
<%if(permissionChecker.isOmniadmin()){%>
<a href="<%= chartURL.toString() %>">View More Chart&raquo;</a>
<%}%>
<%
String lifehome = PropsUtil.get("default.liferay.home");

User selUser = UserLocalServiceUtil.getUserById(userId);
List userList = UserUtil.findAll();        
        
        int countSchool=0,countCollege=0,countMainstay=0,countStudent=0,countTeacher=0,countParent=0,countOthers=0,countCollStudent=0,countStaff=0,countCollOthers=0,overAllUsers=0,overAllBlossoms=0,overAllCampus=0,overAllMainstay=0;
        for(int i=0;i<userList.size();i++){
     	   User ur = (User)userList.get(i);
     	   if(ur.getComments().equalsIgnoreCase("school")){
     		   countSchool++;
     	   }else if (ur.getComments().equalsIgnoreCase("college")){
     		   countCollege++;
     		}else if (ur.getComments().equalsIgnoreCase("mainstay")){
      			countMainstay++;
      		}else if (ur.getComments().equalsIgnoreCase("student")){
      			countStudent++;
      		}else if (ur.getComments().equalsIgnoreCase("teacher")){
      			countTeacher++;
      		}else if (ur.getComments().equalsIgnoreCase("parent")){
      			countParent++;
      		}else if (ur.getComments().equalsIgnoreCase("others")){
      			countOthers++;
      		}else if (ur.getComments().equalsIgnoreCase("collStudent")){
      			countCollStudent++;
      		}else if (ur.getComments().equalsIgnoreCase("staff")){
      			countStaff++;
      		}else if (ur.getComments().equalsIgnoreCase("collOthers")){
      			countCollOthers++;
      		}
	overAllUsers=countSchool+countCollege+countMainstay+countStudent+countTeacher+countParent+countOthers+countCollStudent+countStaff+countCollOthers;
	overAllBlossoms=countSchool+countStudent+countTeacher+countParent+countOthers;
	overAllCampus=countCollege+countCollStudent+countStaff+countCollOthers;
	overAllMainstay=countMainstay;	
        } 
  
   	int common=0,academic=0,social=0;
    	common = CommunityExtraUtil.countByCategory(1);
     	academic = CommunityExtraUtil.countByCategory(2);
     	social = CommunityExtraUtil.countByCategory(3); 
	
	int c_school=0, c_college=0, c_mainstay=0, c_benchmark=0, c_ben_sc=0, c_ben_coll=0, c_ben_main=0;
	c_school = CommunityExtraUtil.countByType(1, 1);
	c_college = CommunityExtraUtil.countByType(2, 1);
	c_mainstay = CommunityExtraUtil.countByType(3, 1);
	c_benchmark = CommunityExtraUtil.countByType(4, 1);
	c_ben_sc = CommunityExtraUtil.countByType(5, 1);
	c_ben_coll = CommunityExtraUtil.countByType(6, 1);
	c_ben_main = CommunityExtraUtil.countByType(7, 1);

	int a_school=0, a_college=0, a_mainstay=0, a_benchmark=0, a_ben_sc=0, a_ben_coll=0, a_ben_main=0;
	a_school = CommunityExtraUtil.countByType(1, 2);
	a_college = CommunityExtraUtil.countByType(2, 2);
	a_mainstay = CommunityExtraUtil.countByType(3, 2);
	a_benchmark = CommunityExtraUtil.countByType(4, 2);
	a_ben_sc = CommunityExtraUtil.countByType(5, 2);
	a_ben_coll = CommunityExtraUtil.countByType(6, 2);
	a_ben_main = CommunityExtraUtil.countByType(7, 2);

	int s_school=0, s_college=0, s_mainstay=0, s_benchmark=0, s_ben_sc=0, s_ben_coll=0, s_ben_main=0;
	s_school = CommunityExtraUtil.countByType(1, 3);
	s_college = CommunityExtraUtil.countByType(2, 3);
	s_mainstay = CommunityExtraUtil.countByType(3, 3);
	s_benchmark = CommunityExtraUtil.countByType(4, 3);
	s_ben_sc = CommunityExtraUtil.countByType(5, 3);
	s_ben_coll = CommunityExtraUtil.countByType(6, 3);
	s_ben_main = CommunityExtraUtil.countByType(7, 3);
%>

<%@ page  import="java.awt.*" %>
<%@ page  import="java.io.*" %>
<%@ page  import="org.jfree.chart.*" %>
<%@ page  import="org.jfree.chart.axis.*" %>
<%@ page  import="org.jfree.chart.entity.*" %>
<%@ page  import="org.jfree.chart.labels.*" %>
<%@ page  import="org.jfree.chart.plot.*" %>
<%@ page  import="org.jfree.chart.renderer.category.*" %>
<%@ page  import="org.jfree.chart.urls.*" %>
<%@ page  import="org.jfree.data.category.*" %>
<%@ page  import="org.jfree.data.general.*" %>

<%
// Analytics Chart 
//****************
     DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
	dataset0.addValue(countSchool, "Blossoms("+overAllBlossoms+")","School("+countSchool+")" );
	dataset0.addValue(countStudent, "Blossoms("+overAllBlossoms+")","Student("+countStudent+")" );
	dataset0.addValue(countTeacher, "Blossoms("+overAllBlossoms+")","Teacher("+countTeacher+")" );
	dataset0.addValue(countParent, "Blossoms("+overAllBlossoms+")","Parent("+countParent+")" );  
	dataset0.addValue(countOthers, "Blossoms("+overAllBlossoms+")","Others("+countOthers+")" );

    dataset0.addValue(countCollege, "Campus("+overAllCampus+")", "College("+countCollege+")");  
    dataset0.addValue(countCollStudent, "Campus("+overAllCampus+")", "CollegeStudent("+countCollStudent+")"); 
	dataset0.addValue(countStaff, "Campus("+overAllCampus+")", "Staff("+countStaff+")"); 
    dataset0.addValue(countCollOthers, "Campus("+overAllCampus+")", "Coll_Others("+countCollOthers+")");
    
        dataset0.addValue(countMainstay,"Mainstay("+overAllMainstay+")", "Mainstay("+countMainstay+")"); 
	
	dataset0.addValue(0,"overAllUsers("+overAllUsers+")", ""); 

        JFreeChart chart0 = ChartFactory.createBarChart("Benchamrk Statistics", "Benchmark", "Number", dataset0,
            	PlotOrientation.VERTICAL, true, false, false);
                chart0.setBackgroundPaint(Color.white);
                final CategoryPlot plot0 = chart0.getCategoryPlot();

                plot0.setBackgroundPaint(Color.gray);               
                plot0.setRangeGridlinePaint(Color.white);   
 
        final NumberAxis rangeAxis0 = (NumberAxis) plot0.getRangeAxis();
        rangeAxis0.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        final BarRenderer renderer0 = (BarRenderer) plot0.getRenderer();
        renderer0.setDrawBarOutline(true);

        final GradientPaint gp00 = new GradientPaint(0.0f, 0.0f, Color.blue,0.0f, 0.0f, Color.lightGray);
        final GradientPaint gp10 = new GradientPaint(0.0f, 0.0f, Color.green,0.0f, 0.0f, Color.lightGray);
        final GradientPaint gp20 = new GradientPaint(0.0f, 0.0f, Color.red,0.0f, 0.0f, Color.lightGray);                          
	final GradientPaint gp30 = new GradientPaint(0.0f, 0.0f, Color.white,0.0f, 0.0f, Color.lightGray); 

        renderer0.setSeriesPaint(0, gp00);
        renderer0.setSeriesPaint(1, gp10);
        renderer0.setSeriesPaint(2, gp20); 
	renderer0.setSeriesPaint(3, gp30); 
	

        final CategoryAxis domainAxis0 = plot0.getDomainAxis();
        domainAxis0.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );          

            try {
                final ChartRenderingInfo info0 = new ChartRenderingInfo(new StandardEntityCollection());
                final File file0 = new File(lifehome+"/tomcat/webapps/ROOT/html/portlet/ext/chart/barchart0.png");
		
                ChartUtilities.saveChartAsPNG(file0, chart0, 400, 250, info0);
		
            } catch (Exception e) {
                out.println(e);
            }

// Community Chart 
//****************
     DefaultCategoryDataset dataset = new DefaultCategoryDataset();
	dataset.addValue(common, "Common("+common+")","Common("+common+")" );  
        dataset.addValue(academic, "Academic("+academic+")", "Academic("+academic+")");       
        dataset.addValue(social,"Social("+social+")", "Social("+social+")");  

        JFreeChart chart = ChartFactory.createBarChart("Community Statistics", "Community", "Number", dataset,
            	PlotOrientation.VERTICAL, true, false, false);
                chart.setBackgroundPaint(Color.white);
                final CategoryPlot plot = chart.getCategoryPlot();

                plot.setBackgroundPaint(Color.pink);               
                plot.setRangeGridlinePaint(Color.white);   
 
        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        final BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(true);

        final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue,0.0f, 0.0f, Color.lightGray);
        final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green,0.0f, 0.0f, Color.lightGray);
        final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red,0.0f, 0.0f, Color.lightGray);                          

        renderer.setSeriesPaint(0, gp0);
        renderer.setSeriesPaint(1, gp1);
        renderer.setSeriesPaint(2, gp2); 

        final CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );          

            try {
                final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                final File file1 = new File(lifehome+"/tomcat/webapps/ROOT/html/portlet/ext/chart/barchart.png");
                ChartUtilities.saveChartAsPNG(file1, chart, 400, 240, info);
		
            } catch (Exception e) {
                out.println(e);
            }
//Common Category

     DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
	dataset1.addValue(c_school, "School("+c_school+")", "School("+c_school+")");  
        dataset1.addValue(c_college,"College("+c_college+")","College("+c_college+")"); 
	dataset1.addValue(c_mainstay,"Mainstay("+c_mainstay+")", "Main("+c_mainstay+")");
	dataset1.addValue(c_benchmark,"Benchmark("+c_benchmark+")","Bench("+c_benchmark+")");
	dataset1.addValue(c_ben_sc,"Benchmark_school("+c_ben_sc+")", "b_sc("+c_ben_sc+")");
	dataset1.addValue(c_ben_coll,"Benchmark_college("+c_ben_coll+")","b_coll("+c_ben_coll+")");
	dataset1.addValue(c_ben_main,"Benchmark_mainstay("+c_ben_main+")", "b_main("+c_ben_main+")");         

        JFreeChart chart1 = ChartFactory.createBarChart("Common community", "Common category", "Number", dataset1,
            	PlotOrientation.VERTICAL, true, false, false);
                chart1.setBackgroundPaint(Color.white);
                final CategoryPlot plot1 = chart1.getCategoryPlot();
                plot1.setBackgroundPaint(Color.black);   
 
        final NumberAxis rangeAxis1 = (NumberAxis) plot1.getRangeAxis();
        rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        final BarRenderer renderer1 = (BarRenderer) plot1.getRenderer();
        renderer1.setDrawBarOutline(true);

        final CategoryAxis domainAxis1 = plot1.getDomainAxis();
        domainAxis1.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );
            try {
                final ChartRenderingInfo info1 = new ChartRenderingInfo(new StandardEntityCollection());
                final File file2 = new File(lifehome+"/tomcat/webapps/ROOT/html/portlet/ext/chart/barchart1.png");
                ChartUtilities.saveChartAsPNG(file2, chart1, 400, 250, info1);
		
            } catch (Exception e) {
                out.println(e);
            }   
//Academic Category


     DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
	dataset2.addValue(a_school, "School("+a_school+")", "School("+a_school+")");  
        dataset2.addValue(a_college,"College("+a_college+")","College("+a_college+")"); 
	dataset2.addValue(a_mainstay,"Mainstay("+a_mainstay+")", "Main("+a_mainstay+")");
	dataset2.addValue(a_benchmark,"Benchmark("+a_benchmark+")","Bench("+a_benchmark+")");
	dataset2.addValue(a_ben_sc,"Benchmark_school("+a_ben_sc+")", "b_sc("+a_ben_sc+")");
	dataset2.addValue(a_ben_coll,"Benchmark_college("+a_ben_coll+")","b_coll("+a_ben_coll+")");
	dataset2.addValue(a_ben_main,"Benchmark_mainstay("+a_ben_main+")", "b_main("+a_ben_main+")");         

        JFreeChart chart2 = ChartFactory.createBarChart("Academic community", "Academic category", "Number", dataset2,
            	PlotOrientation.VERTICAL, true, false, false);
                chart2.setBackgroundPaint(Color.white);
                final CategoryPlot plot2 = chart2.getCategoryPlot();
                plot2.setBackgroundPaint(Color.lightGray);   
 
        final NumberAxis rangeAxis2 = (NumberAxis) plot2.getRangeAxis();
        rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        final BarRenderer renderer2 = (BarRenderer) plot2.getRenderer();
        renderer2.setDrawBarOutline(true);

        final CategoryAxis domainAxis2 = plot2.getDomainAxis();
        domainAxis2.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );
            try {
                final ChartRenderingInfo info2 = new ChartRenderingInfo(new StandardEntityCollection());
                final File file3 = new File(lifehome+"/tomcat/webapps/ROOT/html/portlet/ext/chart/barchart2.png");
                ChartUtilities.saveChartAsPNG(file3, chart2, 400, 250, info2);
		
            } catch (Exception e) {
                out.println(e);
            }  
//Social Category

     DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();
	dataset3.addValue(s_school, "School("+s_school+")", "School("+s_school+")");  
        dataset3.addValue(s_college,"College("+s_college+")","College("+s_college+")"); 
	dataset3.addValue(s_mainstay,"Mainstay("+s_mainstay+")", "Main("+s_mainstay+")");
	dataset3.addValue(s_benchmark,"Benchmark("+s_benchmark+")","Bench("+s_benchmark+")");
	dataset3.addValue(s_ben_sc,"Benchmark_school("+s_ben_sc+")", "b_sc("+s_ben_sc+")");
	dataset3.addValue(s_ben_coll,"Benchmark_college("+s_ben_coll+")","b_coll("+s_ben_coll+")");
	dataset3.addValue(s_ben_main,"Benchmark_mainstay("+s_ben_main+")", "b_main("+s_ben_main+")");         

        JFreeChart chart3 = ChartFactory.createBarChart("Social community", "Social category", "Number", dataset3,
            	PlotOrientation.VERTICAL, true, false, false);
                chart3.setBackgroundPaint(Color.white);
                final CategoryPlot plot3 = chart3.getCategoryPlot();
                plot3.setBackgroundPaint(Color.cyan);   
 
        final NumberAxis rangeAxis3 = (NumberAxis) plot3.getRangeAxis();
        rangeAxis3.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        final BarRenderer renderer3 = (BarRenderer) plot3.getRenderer();
        renderer3.setDrawBarOutline(true);

        final CategoryAxis domainAxis3 = plot3.getDomainAxis();
        domainAxis3.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );
            try {
                final ChartRenderingInfo info3 = new ChartRenderingInfo(new StandardEntityCollection());
                final File file4 = new File(lifehome+"/tomcat/webapps/ROOT/html/portlet/ext/chart/barchart3.png");
                ChartUtilities.saveChartAsPNG(file4, chart3, 400, 250, info3);
		
            } catch (Exception e) {
                out.println(e);
            } 

 //School details

if(selUser.getComments().equals("school")){	
     School sc = SchoolUtil.fetchByLoginId(selUser.getScreenName());		
     sch(sc.getSchoolId());	
     
}
if(selUser.getComments().equals("student")){	
     Student st = StudentUtil.fetchByLoginId(selUser.getScreenName());
     sch(st.getSchoolId());	
}

if(selUser.getComments().equals("teacher")){	
     Teacher tr = TeacherUtil.fetchByLoginId(selUser.getScreenName());
     sch(tr.getSchoolId());	
}
if(selUser.getComments().equals("parent")){	
     Parent pr = ParentUtil.fetchByLoginId(selUser.getScreenName());
     sch(pr.getSchoolId());	
}
if(selUser.getComments().equals("college")){	
     College cg = CollegeUtil.fetchByLoginId(selUser.getScreenName());
     coll(cg.getCollegeId());
}
if(selUser.getComments().equals("collStudent")){
     CollStudent ctt = CollStudentUtil.fetchByLoginId(selUser.getScreenName());	     
     coll(ctt.getCollegeId());
}
if(selUser.getComments().equals("staff")){	
     Staff sf = StaffUtil.fetchByLoginId(selUser.getScreenName());
     coll(sf.getCollegeId());
}
%>
<%!
private void sch(long ssId) throws Exception {
 School school = SchoolLocalServiceUtil.getSchool(ssId);
String lifehome1 = PropsUtil.get("default.liferay.home");
     DefaultCategoryDataset dataset4 = new DefaultCategoryDataset();	 
        dataset4.addValue(school.getNoOfStudents(),"Students("+school.getNoOfStudents()+")","Students("+school.getNoOfStudents()+")"); 
	dataset4.addValue(school.getNoOfTeachers(),"Teachers("+school.getNoOfTeachers()+")", "Teachers("+school.getNoOfTeachers()+")");
	
        JFreeChart chart4 = ChartFactory.createBarChart(""+school.getName()+"  School", ""+school.getName()+"  School", "Number", dataset4,
            	PlotOrientation.VERTICAL, true, false, false);
                chart4.setBackgroundPaint(Color.white);
                final CategoryPlot plot4 = chart4.getCategoryPlot();
                plot4.setBackgroundPaint(Color.black);   
 
        final NumberAxis rangeAxis4 = (NumberAxis) plot4.getRangeAxis();
        rangeAxis4.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        final BarRenderer renderer4 = (BarRenderer) plot4.getRenderer();
        renderer4.setDrawBarOutline(true);

        final CategoryAxis domainAxis4 = plot4.getDomainAxis();
        domainAxis4.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );
            try {
                final ChartRenderingInfo info4 = new ChartRenderingInfo(new StandardEntityCollection());
                final File file5 = new File(lifehome1+"/tomcat/webapps/ROOT/html/portlet/ext/chart/barchart4.png");
                ChartUtilities.saveChartAsPNG(file5, chart4, 400, 250, info4);
		
            } catch (Exception e) {
                
            } 	
}

private void coll(long clId) throws Exception {
 College coll = CollegeLocalServiceUtil.getCollege(clId);	
String lifehome2 = PropsUtil.get("default.liferay.home");
     DefaultCategoryDataset dataset5 = new DefaultCategoryDataset();	 
        dataset5.addValue(coll.getNoOfStudents(),"Students("+coll.getNoOfStudents()+")","Students("+coll.getNoOfStudents()+")"); 
	dataset5.addValue(coll.getNoOfStaffs(),"Staffs("+coll.getNoOfStaffs()+")", "Staffs("+coll.getNoOfStaffs()+")");
	
        JFreeChart chart5 = ChartFactory.createBarChart(""+coll.getName()+"  College", ""+coll.getName()+"  College", "Number", dataset5,
            	PlotOrientation.VERTICAL, true, false, false);
                chart5.setBackgroundPaint(Color.white);
                final CategoryPlot plot5 = chart5.getCategoryPlot();
                plot5.setBackgroundPaint(Color.black);   
 
        final NumberAxis rangeAxis5 = (NumberAxis) plot5.getRangeAxis();
        rangeAxis5.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        
        final BarRenderer renderer5 = (BarRenderer) plot5.getRenderer();
        renderer5.setDrawBarOutline(true);

        final CategoryAxis domainAxis5 = plot5.getDomainAxis();
        domainAxis5.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0) );
            try {
                final ChartRenderingInfo info5 = new ChartRenderingInfo(new StandardEntityCollection());
                final File file6 = new File(lifehome2+"/tomcat/webapps/ROOT/html/portlet/ext/chart/barchart5.png");
                ChartUtilities.saveChartAsPNG(file6, chart5, 400, 250, info5);		
            } catch (Exception e) {
                
            } 	
}

%>

<table align="center" cellspacing="10" cellpadding="3">
<tr>
<td>
<img src="/html/portlet/ext/chart/barchart0.png">
<%if(selUser.getComments().equals("school")||selUser.getComments().equals("student")||selUser.getComments().equals("teacher")||selUser.getComments().equals("parent")){%>
<img src="/html/portlet/ext/chart/barchart4.png">
<%}%>
<%if(selUser.getComments().equals("college")||selUser.getComments().equals("collStudent")||selUser.getComments().equals("staff")){%>
<img src="/html/portlet/ext/chart/barchart5.png">
<%}%>
</tr>
</table>

     
